package me.zxk.smartagriculture.dto.news;

import lombok.Data;

import java.time.LocalDateTime;

/**
 * 新闻列表响应DTO
 */
@Data
public class NewsListResponse {

    private Long id;
    private String title;
    private String summary;
    private String coverImage;
    private String author;
    private LocalDateTime publishTime;
    private Integer viewCount;
    private Integer likeCount;
    private Integer commentCount;
    private Boolean isLiked = false; // 当前用户是否已点赞

    /**
     * 从实体转换为列表响应DTO
     */
    public static NewsListResponse fromEntity(me.zxk.smartagriculture.entity.News news) {
        NewsListResponse response = new NewsListResponse();
        response.setId(news.getId());
        response.setTitle(news.getTitle());
        response.setSummary(news.getSummary());
        response.setCoverImage(news.getCoverImage());
        response.setAuthor(news.getAuthor());
        response.setPublishTime(news.getPublishTime());
        response.setViewCount(news.getViewCount());
        response.setLikeCount(news.getLikeCount());
        response.setCommentCount(news.getCommentCount());
        return response;
    }
}
